/**
 * @title HHUserAction.java 
 * @description 	后台用户管理模块动作类文件
 * @create 			2012-7-26 上午10:35:17 By xjiujiu
 * @package 		apps.admin.action
 * @copyright 		Copyright (c) 2011-2012 http://xyrj.hhtc.edu.cn.com. All right reserved
 * @version        $Id$
 * XYRJ-Java-Project
 */

package apps.admin.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import system.pojo.HHDiffpeoPojo;

import apps.admin.form.HHDiffpeoForm;
import apps.admin.model.HHModelBaseModel;
import apps.admin.model.HHDiffpeoModel;

import com.xyrj.exception.HHValidateException;
import com.xyrj.mvc.HHAction;
import com.xyrj.utils.HHDatetime;

/**
 * 企业后台管理模块动作类 最新动态类型模块(新闻类型)
 * 
 * @description
 * 
 * @classname HHUserAction
 * @author xjiujiu<xjiujiu@foxmail.com>
 * @date 2012-7-26 上午10:35:17
 * @version 1.0
 */
public class HHDiffpeoAction extends HHActionBaseAction {

	/**
	 * @see HHAction#HHAction(HttpServletRequest, HttpServletResponse)
	 */
	public HHDiffpeoAction(HttpServletRequest request,
			HttpServletResponse response) {
		super(request, response);

		this._pojo = new HHDiffpeoPojo();
	}

	/**
	 * @see HHActionBaseAction#addview()
	 */
	public void addview() {
		super.addview();
		this._assignParentList(new HHDiffpeoModel());

		this._view.display("admin/diffpeo/info.jsp");
	}

	/**
	 * 添加用户动作
	 * 
	 * @description
	 * 
	 * @title add
	 * @return void
	 */
	public void add() {
		try {
			this._assginPojoByAdd();
			HHDiffpeoForm addDiffpeoForm = new HHDiffpeoForm();
			addDiffpeoForm.validate(this._pojo);
			this._pojo.setField("edit_time", HHDatetime.getNow());
			this._pojo.setField("create_time", HHDatetime.getNow());
			this._pojo.setField("author",
					this._view.getSessionAttr("xyrj_user_name"));
			HHDiffpeoModel caseModel = this._initModel();
			if (0 < caseModel.add(this._pojo)) {
				this._view.alertAndGoBack("添加成功");
			} else {
				this._view.alertAndGoBack("添加失败！请联系管理员～");
			}
		} catch (HHValidateException ex) {
			this._view.alertAndGoBack(ex.getMessage());
		}
	}

	/**
	 * @see HHActionBaseAction#editview()
	 */
	public void editview() {
		super.editview();
		this._assignParentList(new HHDiffpeoModel());

		this._view.display("admin/diffpeo/info.jsp");
	}

	/**
	 * 提交用户修改
	 * 
	 * @description
	 * 
	 * @title edit
	 * @return void
	 */
	public void edit() {
		try {
			this._assginPojoByEdit();
			HHDiffpeoForm editDiffpeoForm = new HHDiffpeoForm();
			editDiffpeoForm.validate(this._pojo);
			this._pojo.setField("edit_time", HHDatetime.getNow());
			this._pojo.setField("author",
					this._view.getSessionAttr("xyrj_user_name"));
			HHDiffpeoModel caseModel = this._initModel();
			if (0 < caseModel.edit(this._pojo)) {
				this._deleteOldFile("image_path");
				this._view.alertAndRefresh("更新成功");
			} else {
				this._view.alertAndRefresh("更新失败！请联系管理员～");
			}
		} catch (HHValidateException ex) {
			this._view.alertAndGoBack(ex.getMessage());
		}
	}

	/**
	 * @see HHModelBaseModel#initModel()
	 */
	protected HHDiffpeoModel _initModel() {
		return new HHDiffpeoModel(this._pojo);
	}

	/*
	 * (非 Javadoc) <p>初始化当前模块的父类模块实例</p>
	 * 
	 * <p>description: </p>
	 * 
	 * @title _initParentModel
	 * 
	 * @return
	 * 
	 * @see apps.admin.action.HHActionBaseAction#_initParentModel()
	 */
	@Override
	protected HHDiffpeoModel _initParentModel() {
		return new HHDiffpeoModel();
	}

}
